import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useMaterial = defineStore('material', () => {
    const select_material = ref([]);
    function addSelect(item) {
        select_material.value.forEach((el, index) => {
            if (item.id == el.name) {
                select_material.value[index].number = el.number + item.number;
                return;
            }
        })
        select_material.value.push(item);
    }
    function deleteSelect(item) {
        select_material.value.forEach((el, index) => {
            if (item.id == el.name) {
                select_material.value.splice(index, 1)
            }
        })
    }
    return { select_material, addSelect, deleteSelect }
})
